<?php

require_once('../inc/utils.php');

function main()
{
	header('Content-Type: text/plain');
	
	//Make sure we don't wipe the existing site (setup.sql has some DROP TABLES commands)
	global $g_config;
	if(file_exists('../data/lock.setup'))
	{
		if($g_config['repeat_setup_allowed'])
			echo 'Warning: purging existing site contents' . "\n\n";
		else
			die('Site already configured, delete data/lock.setup if you want to erase all current content and reinitialize' . "\n\n");
	}
	touch('../data/lock.setup');
	
	//Run the setup commands
	$queries = explode(';', file_get_contents('../setup/setup.sql'));
	foreach($queries as $q)
	{
		$q = trim($q);
		if($q != '')
			dbquery($q . ';');
	}
	
	echo 'You may now log in with default credentials admin:admin';
}

?>
